package com.itheimaoa.service.process.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheimaoa.domain.process.Audition;
import com.itheimaoa.service.base.impl.CommonServiceImpl;
import com.itheimaoa.service.process.IAuditionService;

@Service
@Transactional
public class AuditionServiceImpl extends CommonServiceImpl<Audition> implements IAuditionService {
	
	
	
	
	@Override
	public void saveEntity(Audition t) {
		super.saveEntity(t);
	}

	@Override
	public void updateEntity(Audition t) {
		super.updateEntity(t);
	}

	@Override
	@Transactional(readOnly = true)
	public Audition findApplyId(String applyId) {
		String jpql = " from Audition o where o.apply.aid = ? order by o.uptime desc";
		List<Audition> auditions = this.hibernateTemplate.find(jpql, applyId);
		if (auditions != null && auditions.size() > 0) {
			auditions.get(0);
		}
		return null;
	}

	@Override
	@Transactional(readOnly = true)
	public Audition findAuditionByApplyId(String applyId) {
		String jpql = " from Audition o where o.apply.aid = ?";
		List<Audition> auditions = this.hibernateTemplate.find(jpql, applyId);
		if (auditions != null && auditions.size() > 0) {
			for (Audition a : auditions) {
				if (!a.getAgree()) {
					return a;
				}
			}
		}
		return null;
	}

	@Override
	@Transactional(readOnly = true)
	public List<Audition> findAuditionsByApplyId(String applyId) {
		String jpql = " from Audition o where o.apply.aid = ? order by o.uptime asc";
		List<Audition> auditions = this.hibernateTemplate.find(jpql, applyId);
		return auditions;
	}

}
